package hash;

import interfaces.*;
import common.*;
import java.util.List;
import java.util.LinkedList;

public class SimpleProcessor implements IStreamProcessor{
    int paneSize=2;
    int windowSize=4;
    double minSupport=1;
    
    int transCounter=0;
       
    public Table table;
    TransactionItems[] transItem;
    
    @Override
    public void init(){
        table = new Table(minSupport, windowSize);
        
        transItem = new TransactionItems[windowSize];
        for (int i=0; i<transItem.length; ++i){
            transItem[i] = new TransactionItems();
        }
    }
    
    @Override
    public boolean setWindow(int window, int pane){
        if (((window % pane)!=0) || (window<=0) || (pane<=0)){
            this.windowSize = 4;
            this.paneSize = 2;
            return false;
        }
        else{
            this.windowSize = window;
            this.paneSize = pane;
            return true;
        }      
    }
    
    @Override
    public boolean setSupport(double minSupport){
        if ((minSupport > 1) || (minSupport <= 0)){
            this.minSupport = 1;
            return false;
        }
        else{
            this.minSupport = minSupport;
            return false;
        }
            
    }
    
    @Override
    public List<Match> addTransaction(ITransaction transaction){
    
        if ((++transCounter) == windowSize) 
            transCounter=0;
        
        transItem[transCounter].removeFromWindow();
        transItem[transCounter] = table.addTransaction(transaction);
                
        if ( (transCounter % paneSize) == 0 ){
            table.removeEmpty();
            return table.getPatterns(transaction.emptyImplementation());
        }
        else
            return null;
    }
}
